home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / dropde-2.zip / WEAPONS.QC < prev    next >
Text File  |  1996-09-27  |  37KB  |  1,656 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. //Flamethrower
  10. void () W_FireFlame;
  11.  
  12. // DD functions & code.
  13. float actual_team1 = 5;
  14. float actual_team2 = 13;
  15. float actual_team3 = 1;
  16. float actual_team4 = 4;
  17.  
  18. float IT_time;
  19. float tag_wait_time;
  20.  
  21. float assigned_team;
  22. string color_team;
  23. string team_name;
  24. float skin_team;
  25. string skin_name;
  26.  
  27.  
  28. void (float actual_team) TeamName =
  29. {
  30.     if (actual_team == actual_team1)
  31.         team_name = "RED";
  32.     else if (actual_team == actual_team2)
  33.         team_name = "YELLOW";
  34.     else if (actual_team == actual_team3)
  35.         team_name = "WHITE";
  36.     else
  37.         team_name = "GREEN";
  38. };
  39.  
  40.  
  41. void (float skin_number) SkinName =
  42. {
  43.     if (skin_number == 0)
  44.         skin_name = "Default Quake";
  45.     else if (skin_number == 1)
  46.         skin_name = "Duke Nukem 3d";
  47.     else if (skin_number == 2)
  48.         skin_name = "Toad";
  49.     else if (skin_number == 3)
  50.         skin_name = "Stormtrooper";
  51.     else if (skin_number == 4)
  52.         skin_name = "Max";
  53.     else if (skin_number == 5)
  54.         skin_name = "Terminator";
  55.     else if (skin_number == 6)
  56.         skin_name = "Judge Dredd";
  57.     else if (skin_number == 7)
  58.         skin_name = "Camouflaged Soldier";
  59.     else if (skin_number == 8)
  60.         skin_name = "Captain Picard";
  61.     else if (skin_number == 9)
  62.         skin_name = "Wizard";
  63.     else if (skin_number == 10)
  64.         skin_name = "Predator";
  65.     else if (skin_number == 11)
  66.         skin_name = "Skeleton";
  67.     else if (skin_number == 12)
  68.         skin_name = "Wan-Fu";
  69.     else if (skin_number == 13)
  70.         skin_name = "Henry Rollins";
  71.     else if (skin_number == 14)
  72.         skin_name = "He-Man";
  73.     else if (skin_number == 15)
  74.         skin_name = "Boba";
  75.     else if (skin_number == 16)
  76.         skin_name = "Superman";
  77.     else if (skin_number == 17)
  78.         skin_name = "Cop";
  79.     else if (skin_number == 18)
  80.         skin_name = "The Flash";
  81.     else
  82.         skin_name = "Unknown";
  83. };
  84.  
  85.  
  86. void (float team_number, float actual_team) ConfigTeam =
  87. {
  88.     if (team_number == 1 || actual_team == actual_team1)
  89.     {
  90.         assigned_team = actual_team1;
  91.         color_team = "color 4 4\n";
  92.         skin_team = 0;
  93.     }
  94.     else if (team_number == 2 || actual_team == actual_team2)
  95.     {
  96.         assigned_team = actual_team2;
  97.         color_team = "color 12 12\n";
  98.         skin_team = 1;
  99.     }
  100.     else if (team_number == 3 || actual_team == actual_team3)
  101.     {
  102.         assigned_team = actual_team3;
  103.         color_team = "color 0 0\n";
  104.         skin_team = 3;
  105.     }
  106.     else
  107.     {
  108.         assigned_team = actual_team4;
  109.         color_team = "color 3 3\n";
  110.         skin_team = 2;
  111.     }
  112.     TeamName(assigned_team);
  113.     SkinName(skin_team);
  114. };
  115.  
  116.  
  117. void (float team_number, float actual_team) SetTeam =
  118. {
  119.     ConfigTeam(team_number, actual_team);
  120.  
  121.     sprint(self, "You have been assigned to the ");
  122.     sprint(self, team_name);
  123.     sprint(self, " team (");
  124.     sprint(self, skin_name);
  125.     sprint(self, " Skin).\n");
  126.  
  127.     stuffcmd(self, color_team);
  128.     self.start_team = assigned_team;
  129.     parm11 = assigned_team;
  130.     self.team = assigned_team;
  131.     self.skin = skin_team;
  132.     parm10 = skin_team;
  133. };
  134.  
  135.  
  136. void (float team_number, float actual_team) ResetTeam =
  137. {
  138.     ConfigTeam(team_number, actual_team);
  139.  
  140.     sprint(self, "You are a member of the ");
  141.     sprint(self, team_name);
  142.     sprint(self, " team (");
  143.     sprint(self, skin_name);
  144.     sprint(self, " Skin).\n");
  145.  
  146.     stuffcmd(self, color_team);
  147.     self.start_team = assigned_team;
  148.     parm11 = assigned_team;
  149.     self.team = assigned_team;
  150.     self.skin = skin_team;
  151.     parm10 = skin_team;
  152. };
  153.  
  154.  
  155. // called by worldspawn
  156. void() W_Precache =
  157. {
  158.   precache_sound ("hknight/hit.wav");  // flamethrower
  159.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  160.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  161.     precache_sound ("weapons/sgun1.wav");
  162.     precache_sound ("weapons/guncock.wav");    // player shotgun
  163.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  164.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  165.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  166.     precache_sound ("weapons/spike2.wav");    // super spikes
  167.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  168.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  169.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  170.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  171.  
  172.   precache_sound2 ("blob/land1.wav");     // chain go splorch!
  173.   precache_sound ("plats/medplat1.wav");  // chain cranking out
  174.   precache_sound ("doors/ddoor1.wav");    // chain cranking in
  175.     precache_sound ("items/protect3.wav");
  176.     precache_sound ("items/damage3.wav");
  177. };
  178.  
  179. float() crandom =
  180. {
  181.     return 2*(random() - 0.5);
  182. };
  183.  
  184. /*
  185. ================
  186. W_FireAxe
  187. ================
  188. */
  189. void() W_FireAxe =
  190. {
  191.     local    vector    source;
  192.     local    vector    org;
  193.  
  194.     source = self.origin + '0 0 16';
  195.     traceline (source, source + v_forward*64, FALSE, self);
  196.     if (trace_fraction == 1.0)
  197.         return;
  198.     
  199.     org = trace_endpos - v_forward*4;
  200.  
  201.     if (trace_ent.takedamage)
  202.     {
  203.         sound (self, CHAN_WEAPON, "zombie/z_hit.wav", 1, ATTN_NORM);
  204.         trace_ent.axhitme = 1;
  205.         SpawnBlood (org, '0 0 0', 20);
  206.         T_Damage (trace_ent, self, self, 20);
  207.     }
  208.     else
  209.     {    // hit wall
  210.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  211.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  212.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  213.         WriteCoord (MSG_BROADCAST, org_x);
  214.         WriteCoord (MSG_BROADCAST, org_y);
  215.         WriteCoord (MSG_BROADCAST, org_z);
  216.     }
  217. };
  218.  
  219.  
  220. //============================================================================
  221.  
  222.  
  223. vector() wall_velocity =
  224. {
  225.     local vector    vel;
  226.     
  227.     vel = normalize (self.velocity);
  228.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  229.     vel = vel + 2*trace_plane_normal;
  230.     vel = vel * 200;
  231.     
  232.     return vel;
  233. };
  234.  
  235.  
  236. /*
  237. ================
  238. SpawnMeatSpray
  239. ================
  240. */
  241. void(vector org, vector vel) SpawnMeatSpray =
  242. {
  243.     local    entity missile, mpuff;
  244.     local    vector    org;
  245.  
  246.     missile = spawn ();
  247.     missile.owner = self;
  248.     missile.movetype = MOVETYPE_BOUNCE;
  249.     missile.solid = SOLID_NOT;
  250.  
  251.     makevectors (self.angles);
  252.  
  253.     missile.velocity = vel;
  254.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  255.  
  256.     missile.avelocity = '3000 1000 2000';
  257.     
  258. // set missile duration
  259.     missile.nextthink = time + 1;
  260.     missile.think = SUB_Remove;
  261.  
  262.     setmodel (missile, "progs/zom_gib.mdl");
  263.     setsize (missile, '0 0 0', '0 0 0');        
  264.     setorigin (missile, org);
  265. };
  266.  
  267. /*
  268. ================
  269. SpawnBlood
  270. ================
  271. */
  272. void(vector org, vector vel, float damage) SpawnBlood =
  273. {
  274.     particle (org, vel*0.1, 73, damage*2);
  275. };
  276.  
  277. /*
  278. ================
  279. spawn_touchblood
  280. ================
  281. */
  282. void(float damage) spawn_touchblood =
  283. {
  284.     local vector    vel;
  285.  
  286.     vel = wall_velocity () * 0.2;
  287.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  288. };
  289.  
  290.  
  291. /*
  292. ================
  293. SpawnChunk
  294. ================
  295. */
  296. void(vector org, vector vel) SpawnChunk =
  297. {
  298.     particle (org, vel*0.02, 0, 10);
  299. };
  300.  
  301. /*
  302. ==============================================================================
  303.  
  304. MULTI-DAMAGE
  305.  
  306. Collects multiple small damages into a single damage
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. entity    multi_ent;
  312. float    multi_damage;
  313.  
  314. void() ClearMultiDamage =
  315. {
  316.     multi_ent = world;
  317.     multi_damage = 0;
  318. };
  319.  
  320. void() ApplyMultiDamage =
  321. {
  322.     if (!multi_ent)
  323.         return;
  324.     T_Damage (multi_ent, self, self, multi_damage);
  325. };
  326.  
  327. void(entity hit, float damage) AddMultiDamage =
  328. {
  329.     if (!hit)
  330.         return;
  331.     
  332.     if (hit != multi_ent)
  333.     {
  334.         ApplyMultiDamage ();
  335.         multi_damage = damage;
  336.         multi_ent = hit;
  337.     }
  338.     else
  339.         multi_damage = multi_damage + damage;
  340. };
  341.  
  342. /*
  343. ==============================================================================
  344.  
  345. BULLETS
  346.  
  347. ==============================================================================
  348. */
  349.  
  350. /*
  351. ================
  352. TraceAttack
  353. ================
  354. */
  355. void(float damage, vector dir) TraceAttack =
  356. {
  357.     local    vector    vel, org;
  358.     
  359.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  360.     vel = vel + 2*trace_plane_normal;
  361.     vel = vel * 200;
  362.  
  363.     org = trace_endpos - dir*4;
  364.  
  365.     if (trace_ent.takedamage)
  366.     {
  367.         SpawnBlood (org, vel*0.2, damage);
  368.         AddMultiDamage (trace_ent, damage);
  369.     }
  370.     else
  371.     {
  372.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  373.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  374.         WriteCoord (MSG_BROADCAST, org_x);
  375.         WriteCoord (MSG_BROADCAST, org_y);
  376.         WriteCoord (MSG_BROADCAST, org_z);
  377.     }
  378. };
  379.  
  380. /*
  381. ================
  382. FireBullets
  383.  
  384. Used by shotgun, super shotgun, and enemy soldier firing
  385. Go to the trouble of combining multiple pellets into a single damage call.
  386. ================
  387. */
  388. void(float shotcount, vector dir, vector spread) FireBullets =
  389. {
  390.     local    vector direction;
  391.     local    vector    src;
  392.     
  393.     makevectors(self.v_angle);
  394.  
  395.     src = self.origin + v_forward*10;
  396.     src_z = self.absmin_z + self.size_z * 0.7;
  397.  
  398.     ClearMultiDamage ();
  399.     while (shotcount > 0)
  400.     {
  401.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  402.  
  403.         traceline (src, src + direction*2048, FALSE, self);
  404.         if (trace_fraction != 1.0)
  405.             TraceAttack (4, direction);
  406.  
  407.         shotcount = shotcount - 1;
  408.     }
  409.     ApplyMultiDamage ();
  410. };
  411.  
  412. /*
  413. ================
  414. W_FireShotgun
  415. ================
  416. */
  417. void() W_FireShotgun =
  418. {
  419.     local vector dir;
  420.  
  421.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);
  422.  
  423.     self.punchangle_x = -2;
  424.     
  425.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  426.     dir = aim (self, 100000);
  427.     FireBullets (6, dir, '0.04 0.04 0');
  428. };
  429.  
  430.  
  431. /*
  432. ================
  433. W_FireSuperShotgun
  434. ================
  435. */
  436. void() W_FireSuperShotgun =
  437. {
  438.     local vector dir;
  439.  
  440.     if (self.currentammo == 1)
  441.     {
  442.         W_FireShotgun ();
  443.         return;
  444.     }
  445.  
  446.     sound (self, CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);
  447.  
  448.     self.punchangle_x = -4;
  449.     
  450.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  451.     dir = aim (self, 100000);
  452.     FireBullets (14, dir, '0.14 0.08 0');
  453. };
  454.  
  455.  
  456. /*
  457. ==============================================================================
  458.  
  459. ROCKETS
  460.  
  461. ==============================================================================
  462. */
  463.  
  464. void()    s_explode1    =    [0,        s_explode2] {};
  465. void()    s_explode2    =    [1,        s_explode3] {};
  466. void()    s_explode3    =    [2,        s_explode4] {};
  467. void()    s_explode4    =    [3,        s_explode5] {};
  468. void()    s_explode5    =    [4,        s_explode6] {};
  469. void()    s_explode6    =    [5,        SUB_Remove] {};
  470.  
  471. void() BecomeExplosion =
  472. {
  473.     self.movetype = MOVETYPE_NONE;
  474.     self.velocity = '0 0 0';
  475.     self.touch = SUB_Null;
  476.     setmodel (self, "progs/s_explod.spr");
  477.     self.solid = SOLID_NOT;
  478.     s_explode1 ();
  479. };
  480.  
  481. void() MissileExplode =
  482. {
  483.     if (other.health)
  484.     {
  485.         local float    dam;
  486.         dam = 100 + random() * 20;
  487.         if (other.classname == "monster_shambler")
  488.             dam = dam * 0.5;    // mostly immune
  489.         T_Damage (other, self, self.owner, dam);
  490.     }
  491.  
  492.     // don't do radius damage to the other, because all the damage
  493.     // was done in the impact
  494.     T_RadiusDamage (self, self.owner, 120, other);
  495.  
  496. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  497.     self.origin = self.origin - 8*normalize(self.velocity);
  498.  
  499.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  500.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  501.     WriteCoord (MSG_BROADCAST, self.origin_x);
  502.     WriteCoord (MSG_BROADCAST, self.origin_y);
  503.     WriteCoord (MSG_BROADCAST, self.origin_z);
  504.  
  505.     BecomeExplosion ();
  506. };
  507.  
  508. void() T_MissileTouch =
  509. {
  510.     if (other == self.owner)
  511.         return;        // don't explode on owner
  512.  
  513.     if (pointcontents(self.origin) == CONTENT_SKY)
  514.     {
  515.         remove(self);
  516.         return;
  517.     }
  518.  
  519.     MissileExplode();
  520. };
  521.  
  522.  
  523.  
  524. /*
  525. ================
  526. W_FireRocket
  527. ================
  528. */
  529. void() W_FireRocket =
  530. {
  531.     local    entity missile, mpuff;
  532.  
  533.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  534.  
  535.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  536.  
  537.     self.punchangle_x = -2;
  538.  
  539.     missile = spawn ();
  540.     missile.owner = self;
  541.     missile.movetype = MOVETYPE_FLYMISSILE;
  542.     missile.solid = SOLID_BBOX;
  543.  
  544. // set missile speed    
  545.  
  546.     makevectors (self.v_angle);
  547.     missile.velocity = aim(self, 1000);
  548.     missile.velocity = missile.velocity * 1000;
  549.     missile.angles = vectoangles(missile.velocity);
  550.  
  551.     missile.touch = T_MissileTouch;
  552.  
  553. // set missile duration
  554.     missile.nextthink = time + 5;
  555.     missile.think = MissileExplode;
  556.  
  557.     setmodel (missile, "progs/missile.mdl");
  558.     setsize (missile, '0 0 0', '0 0 0');
  559.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  560. };
  561.  
  562. /*
  563. ===============================================================================
  564.  
  565. LIGHTNING
  566.  
  567. ===============================================================================
  568. */
  569.  
  570. /*
  571. =================
  572. LightningDamage
  573. =================
  574. */
  575. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  576. {
  577.     local entity        e1, e2;
  578.     local vector        f;
  579.     
  580.     f = p2 - p1;
  581.     normalize (f);
  582.     f_x = 0 - f_y;
  583.     f_y = f_x;
  584.     f_z = 0;
  585.     f = f*16;
  586.  
  587.     e1 = e2 = world;
  588.  
  589.     traceline (p1, p2, FALSE, self);
  590.     if (trace_ent.takedamage)
  591.     {
  592.         particle (trace_endpos, '0 0 100', 225, damage*4);
  593.         T_Damage (trace_ent, from, from, damage);
  594.         if (self.classname == "player")
  595.         {
  596.             if (other.classname == "player")
  597.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  598.         }
  599.     }
  600.     e1 = trace_ent;
  601.  
  602.     traceline (p1 + f, p2 + f, FALSE, self);
  603.     if (trace_ent != e1 && trace_ent.takedamage)
  604.     {
  605.         particle (trace_endpos, '0 0 100', 225, damage*4);
  606.         T_Damage (trace_ent, from, from, damage);
  607.     }
  608.     e2 = trace_ent;
  609.  
  610.     traceline (p1 - f, p2 - f, FALSE, self);
  611.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  612.     {
  613.         particle (trace_endpos, '0 0 100', 225, damage*4);
  614.         T_Damage (trace_ent, from, from, damage);
  615.     }
  616. };
  617.  
  618.  
  619. void() W_FireLightning =
  620. {
  621.     local    vector org;
  622.  
  623.     if (self.ammo_cells < 1)
  624.     {
  625.         self.weapon = W_BestWeapon ();
  626.         W_SetCurrentAmmo ();
  627.         return;
  628.     }
  629.  
  630. // explode if under water
  631.     if (self.waterlevel > 1)
  632.     {
  633. //        T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  634. // Only players near and in water will be harmed by discharges.
  635.         T_WaterRadiusDamage (self, self, 5 * self.ammo_cells
  636.                 , 250, world);
  637.         self.ammo_cells = 0;
  638.         W_SetCurrentAmmo ();
  639.         return;
  640.     }
  641.  
  642.     if (self.t_width < time)
  643.     {
  644.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  645.         self.t_width = time + 0.6;
  646.     }
  647.     self.punchangle_x = -2;
  648.  
  649.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  650.  
  651.     org = self.origin + '0 0 16';
  652.     
  653.     traceline(org, org + v_forward * 600, TRUE, self);
  654.  
  655.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  656.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  657.     WriteEntity (MSG_BROADCAST, self);
  658.     WriteCoord (MSG_BROADCAST, org_x);
  659.     WriteCoord (MSG_BROADCAST, org_y);
  660.     WriteCoord (MSG_BROADCAST, org_z);
  661.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  662.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  663.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  664.  
  665.   // If shooting into water, all players in that water will take damage.
  666.     if (trace_inwater || trace_ent.waterlevel)
  667.     {
  668.         local vector save_org;
  669.         save_org = self.origin;
  670.         self.origin = trace_endpos;
  671.  
  672.         T_WaterRadiusDamage (self, self, 2, 250, self);
  673.         self.origin = save_org;
  674.   }
  675.     else
  676.         LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  677. };
  678.  
  679.  
  680. //=============================================================================
  681.  
  682.  
  683. void() GrenadeExplode =
  684. {
  685.     T_RadiusDamage (self, self.owner, 120, self);
  686.  
  687.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  688.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  689.     WriteCoord (MSG_BROADCAST, self.origin_x);
  690.     WriteCoord (MSG_BROADCAST, self.origin_y);
  691.     WriteCoord (MSG_BROADCAST, self.origin_z);
  692.  
  693.     BecomeExplosion ();
  694. };
  695.  
  696. void() GrenadeTouch =
  697. {
  698.     if (other == self.owner)
  699.         return;        // don't explode on owner
  700.     if (other.takedamage == DAMAGE_AIM)
  701.     {
  702.         GrenadeExplode();
  703.         return;
  704.     }
  705.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  706.     if (self.velocity == '0 0 0')
  707.         self.avelocity = '0 0 0';
  708. };
  709.  
  710. /*
  711. ================
  712. W_FireGrenade
  713. ================
  714. */
  715. void() W_FireGrenade =
  716. {
  717.     local    entity missile, mpuff;
  718.     
  719.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  720.     
  721.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  722.  
  723.     self.punchangle_x = -2;
  724.  
  725.     missile = spawn ();
  726.     missile.owner = self;
  727.     missile.movetype = MOVETYPE_BOUNCE;
  728.     missile.solid = SOLID_BBOX;
  729.     missile.classname = "grenade";
  730.     
  731. // set missile speed    
  732.  
  733.     makevectors (self.v_angle);
  734.  
  735.     if (self.v_angle_x)
  736.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  737.     else
  738.     {
  739.         missile.velocity = aim(self, 10000);
  740.         missile.velocity = missile.velocity * 600;
  741.         missile.velocity_z = 200;
  742.     }
  743.  
  744.     missile.avelocity = '300 300 300';
  745.  
  746.     missile.angles = vectoangles(missile.velocity);
  747.     
  748.     missile.touch = GrenadeTouch;
  749.     
  750. // set missile duration
  751.     missile.nextthink = time + 2.5;
  752.     missile.think = GrenadeExplode;
  753.  
  754.     setmodel (missile, "progs/grenade.mdl");
  755.     setsize (missile, '0 0 0', '0 0 0');
  756.     setorigin (missile, self.origin);
  757. };
  758.  
  759.  
  760. //=============================================================================
  761.  
  762. void() spike_touch;
  763. void() superspike_touch;
  764.  
  765.  
  766. /*
  767. ===============
  768. launch_spike
  769.  
  770. Generic spike launch.
  771. ===============
  772. */
  773. void(vector org, vector dir) launch_spike =
  774. {
  775.     newmis = spawn ();
  776.     newmis.owner = self;
  777.     newmis.movetype = MOVETYPE_FLYMISSILE;
  778.     newmis.solid = SOLID_BBOX;
  779.  
  780.     newmis.angles = vectoangles(dir);
  781.     
  782.     newmis.touch = spike_touch;
  783.     newmis.classname = "spike";
  784.     newmis.think = SUB_Remove;
  785.     newmis.nextthink = time + 5;
  786.     setmodel (newmis, "progs/spike.mdl");
  787.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  788.     setorigin (newmis, org);
  789.  
  790.     newmis.velocity = dir * 1000;
  791. };
  792.  
  793. void() W_FireSuperSpikes =
  794. {
  795.     local vector    dir;
  796.     local entity    old;
  797.     
  798.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  799.     self.attack_finished = time + 0.2;
  800.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  801.     dir = aim (self, 1000);
  802.     launch_spike (self.origin, dir);
  803.     newmis.touch = superspike_touch;
  804.     setmodel (newmis, "progs/s_spike.mdl");
  805.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  806.     self.punchangle_x = -2;
  807. };
  808.  
  809. void(float ox) W_FireSpikes =
  810. {
  811.     local vector    dir;
  812.     local entity    old;
  813.     
  814.     makevectors (self.v_angle);
  815.     
  816.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  817.     {
  818.         W_FireSuperSpikes ();
  819.         return;
  820.     }
  821.  
  822.     if (self.ammo_nails < 1)
  823.     {
  824.         self.weapon = W_BestWeapon ();
  825.         W_SetCurrentAmmo ();
  826.         return;
  827.     }
  828.  
  829.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  830.     self.attack_finished = time + 0.2;
  831.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  832.     dir = aim (self, 1000);
  833.     launch_spike (self.origin + v_right * ox, dir);
  834.  
  835.     self.punchangle_x = -2;
  836. };
  837.  
  838.  
  839. void(vector org) spawn_tfog;
  840. void(vector org, entity death_owner) spawn_tdeath;
  841.  
  842.  
  843. void() spike_touch =
  844. {
  845. //    if (other == self.owner)
  846. //        return;
  847.  
  848.     if (other.solid == SOLID_TRIGGER)
  849.         return;    // trigger field, do nothing
  850.  
  851.     if (pointcontents(self.origin) != CONTENT_SKY)
  852.     {
  853.         // hit something that bleeds
  854.         if (other.takedamage)
  855.         {
  856.             local float dam;
  857.             if (self.classname == "spike" && self.movetype == MOVETYPE_BOUNCE)
  858.                 dam = ((fabs(self.velocity_x) + fabs(self.velocity_y)
  859.                         + fabs(self.velocity_z)) * 0.006) + random();
  860.             else
  861.                 dam = 9;
  862.             spawn_touchblood (dam);
  863.             T_Damage (other, self, self.owner, dam);
  864.         }
  865.         else
  866.         {
  867.             local float spike;
  868.             if (self.classname == "wizspike")
  869.                 spike = TE_WIZSPIKE;
  870.             else if (self.classname == "knightspike")
  871.                 spike = TE_KNIGHTSPIKE;
  872.             else
  873.                 spike = TE_SPIKE;
  874.             WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  875.             WriteByte (MSG_BROADCAST, spike);
  876.             WriteCoord (MSG_BROADCAST, self.origin_x);
  877.             WriteCoord (MSG_BROADCAST, self.origin_y);
  878.             WriteCoord (MSG_BROADCAST, self.origin_z);
  879.  
  880.             if (ricochet && spike == TE_SPIKE)
  881.             {
  882.                 if (self.movetype == MOVETYPE_FLYMISSILE)
  883.                 {
  884.                     // Back up spike and change it to a bounce move type.
  885.                     traceline(self.origin - (v_forward * 8)
  886.                             , self.origin + (v_forward * 16), TRUE, self);
  887.                     setorigin(self, trace_endpos - (v_forward * 2));
  888.                     self.movetype = MOVETYPE_BOUNCE;
  889.                     self.avelocity = '300 300 300';
  890.                     self.owner = world;  // Now allow spike owner to be hit.
  891.                 }
  892.                 return;
  893.             }
  894.         }
  895.     }
  896.     remove(self);
  897. };
  898.  
  899.  
  900. void() superspike_touch =
  901. {
  902. //    if (other == self.owner)
  903. //        return;
  904.  
  905.     if (other.solid == SOLID_TRIGGER)
  906.         return;    // trigger field, do nothing
  907.  
  908.     if (pointcontents(self.origin) != CONTENT_SKY)
  909.     {
  910.         // hit something that bleeds
  911.         if (other.takedamage)
  912.         {
  913.             local float dam;
  914.             if (self.movetype == MOVETYPE_BOUNCE)
  915.                 dam = ((fabs(self.velocity_x) + fabs(self.velocity_y)
  916.                         + fabs(self.velocity_z)) * 0.01) + random();
  917.             else
  918.                 dam = 18;
  919.             spawn_touchblood (dam);
  920.             T_Damage (other, self, self.owner, dam);
  921.         }
  922.         else
  923.         {
  924.             WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  925.             WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  926.             WriteCoord (MSG_BROADCAST, self.origin_x);
  927.             WriteCoord (MSG_BROADCAST, self.origin_y);
  928.             WriteCoord (MSG_BROADCAST, self.origin_z);
  929.  
  930.             if (ricochet && self.movetype == MOVETYPE_FLYMISSILE)
  931.             {
  932.                 // Back up spike and change it to a bounce move type.
  933.                 traceline(self.origin - (v_forward * 8)
  934.                         , self.origin + (v_forward * 16), TRUE, self);
  935.                 setorigin(self, trace_endpos - (v_forward * 2));
  936.                 self.movetype = MOVETYPE_BOUNCE;
  937.                 self.avelocity = '300 300 300';
  938.                 self.owner = world;  // Now allow spike owner to be hit.
  939.             }
  940.             return;
  941.         }
  942.     }
  943.     remove(self);
  944. };
  945.  
  946.  
  947. /*
  948. ===============================================================================
  949.  
  950. PLAYER WEAPON USE
  951.  
  952. ===============================================================================
  953. */
  954.  
  955. void() W_SetCurrentAmmo =
  956. {
  957.     player_run ();        // get out of any weapon firing states
  958.  
  959.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  960.     
  961.     if (self.weapon == IT_AXE)
  962.     {
  963.         self.currentammo = 0;
  964.         self.weaponmodel = "progs/v_axe.mdl";
  965.         self.weaponframe = 0;
  966.     }
  967.   else if (self.weapon == IT_MORNINGSTAR)
  968.   {
  969.     self.currentammo = 0;
  970.     self.weaponmodel = "progs/v_star.mdl";
  971.     self.weaponframe = 0;
  972.   }
  973.     else if (self.weapon == IT_SHOTGUN)
  974.     {
  975.         self.currentammo = self.ammo_shells;
  976.         self.weaponmodel = "progs/v_shot.mdl";
  977.         self.weaponframe = 0;
  978.         self.items = self.items | IT_SHELLS;
  979.     }
  980.     else if (self.weapon == IT_SUPER_SHOTGUN)
  981.     {
  982.         self.currentammo = self.ammo_shells;
  983.         self.weaponmodel = "progs/v_shot2.mdl";
  984.         self.weaponframe = 0;
  985.         self.items = self.items | IT_SHELLS;
  986.     }
  987.     else if (self.weapon == IT_NAILGUN)
  988.     {
  989.         self.currentammo = self.ammo_nails;
  990.         self.weaponmodel = "progs/v_nail.mdl";
  991.         self.weaponframe = 0;
  992.         self.items = self.items | IT_NAILS;
  993.     }
  994.     else if (self.weapon == IT_SUPER_NAILGUN)
  995.     {
  996.         self.currentammo = self.ammo_nails;
  997.         self.weaponmodel = "progs/v_nail2.mdl";
  998.         self.weaponframe = 0;
  999.         self.items = self.items | IT_NAILS;
  1000.     }
  1001.     else if (self.weapon == IT_GRENADE_LAUNCHER
  1002.             || self.weapon == IT_FLAMETHROWER)
  1003.     {
  1004.         self.currentammo = self.ammo_rockets;
  1005.         self.weaponmodel = "progs/v_rock.mdl";
  1006.         self.weaponframe = 0;
  1007.         self.items = self.items | IT_ROCKETS;
  1008.     }
  1009.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1010.     {
  1011.         self.currentammo = self.ammo_rockets;
  1012.         self.weaponmodel = "progs/v_rock2.mdl";
  1013.         self.weaponframe = 0;
  1014.         self.items = self.items | IT_ROCKETS;
  1015.     }
  1016.     else if (self.weapon == IT_LIGHTNING)
  1017.     {
  1018.         self.currentammo = self.ammo_cells;
  1019.         self.weaponmodel = "progs/v_light.mdl";
  1020.         self.weaponframe = 0;
  1021.         self.items = self.items | IT_CELLS;
  1022.     }
  1023.     else
  1024.     {
  1025.         self.currentammo = 0;
  1026.         self.weaponmodel = "";
  1027.         self.weaponframe = 0;
  1028.     }
  1029. };
  1030.  
  1031. float() W_BestWeapon =
  1032. {
  1033.     local    float    it;
  1034.     
  1035.     it = self.items;
  1036.  
  1037.     if (self.ammo_cells >= 1 && (it & IT_LIGHTNING) && self.waterlevel <= 1 )
  1038.         return IT_LIGHTNING;
  1039.     else if (self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  1040.         return IT_SUPER_NAILGUN;
  1041.     else if (self.ammo_rockets >= 1 && (it & IT_FLAMETHROWER)
  1042.                 && self.waterlevel <= 2 )
  1043.         return IT_FLAMETHROWER;
  1044.     else if (self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  1045.         return IT_SUPER_SHOTGUN;
  1046.     else if (self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  1047.         return IT_NAILGUN;
  1048.     else if (self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  1049.         return IT_SHOTGUN;
  1050.  
  1051. /*
  1052.     else if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  1053.         return IT_ROCKET_LAUNCHER;
  1054.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  1055.         return IT_GRENADE_LAUNCHER;
  1056. */
  1057.  
  1058.     return IT_AXE;
  1059. };
  1060.  
  1061. float() W_CheckNoAmmo =
  1062. {
  1063.     if (self.currentammo >= 1)  // DD change.
  1064.         return TRUE;
  1065.  
  1066.   if (self.weapon == IT_AXE || self.weapon == IT_MORNINGSTAR)
  1067.         return TRUE;
  1068.     
  1069.     self.weapon = W_BestWeapon ();
  1070.  
  1071.     W_SetCurrentAmmo ();
  1072.     
  1073. // drop the weapon down
  1074.     return FALSE;
  1075. };
  1076.  
  1077. /*
  1078. ============
  1079. W_Attack
  1080.  
  1081. An attack impulse can be triggered now
  1082. ============
  1083. */
  1084. void()    player_axe1;
  1085. void()    player_axeb1;
  1086. void()    player_axec1;
  1087. void()    player_axed1;
  1088. void()    player_shot1;
  1089. void()    player_nail1;
  1090. void()    player_light1;
  1091. void()    player_rocket1;
  1092. void()    player_chain1;
  1093. void()  player_chain3;
  1094.  
  1095. void() W_Attack =
  1096. {
  1097.     local    float    r;
  1098.  
  1099.     if (!W_CheckNoAmmo ())
  1100.         return;
  1101.  
  1102.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  1103.     self.show_hostile = time + 1;    // wake monsters up
  1104.  
  1105.     if (self.weapon == IT_AXE)
  1106.     {
  1107.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1108.         r = random();
  1109.         if (r < 0.25)
  1110.             player_axe1 ();
  1111.         else if (r<0.5)
  1112.             player_axeb1 ();
  1113.         else if (r<0.75)
  1114.             player_axec1 ();
  1115.         else
  1116.             player_axed1 ();
  1117.         self.attack_finished = time + 0.5;
  1118.     }
  1119.     else if (self.weapon == IT_SHOTGUN)
  1120.     {
  1121.         player_shot1 ();
  1122.         W_FireShotgun ();
  1123.         self.attack_finished = time + 0.5;
  1124.     }
  1125.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1126.     {
  1127.         player_shot1 ();
  1128.         W_FireSuperShotgun ();
  1129.         self.attack_finished = time + 0.7;
  1130.     }
  1131.     else if (self.weapon == IT_NAILGUN)
  1132.     {
  1133.         player_nail1 ();
  1134.     }
  1135.     else if (self.weapon == IT_SUPER_NAILGUN)
  1136.     {
  1137.         player_nail1 ();
  1138.     }
  1139.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1140.     {
  1141.         player_rocket1();
  1142.         W_FireGrenade();
  1143.         self.attack_finished = time + 0.6;
  1144.     }
  1145.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1146.     {
  1147.         player_rocket1();
  1148.         W_FireRocket();
  1149.         self.attack_finished = time + 0.8;
  1150.     }
  1151.   // Flamethrower
  1152.   else if (self.weapon == IT_FLAMETHROWER)
  1153.     {
  1154.     player_shot1();
  1155.     W_FireFlame();
  1156.     if (self.waterlevel > 2)
  1157.       self.attack_finished = time + 1;
  1158.     else
  1159.       self.attack_finished = time + 0.1;
  1160.     }
  1161.     else if (self.weapon == IT_LIGHTNING)
  1162.     {
  1163.         player_light1();
  1164.         self.attack_finished = time + 0.1;
  1165.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1166.     }
  1167.   else if (self.weapon == IT_MORNINGSTAR)
  1168.   {
  1169.     if (self.hook == world)
  1170.       player_chain1();
  1171.     else
  1172.       player_chain3();
  1173.         self.attack_finished = time + 0.5;
  1174.   }
  1175. };
  1176.  
  1177. /*
  1178. ============
  1179. W_ChangeWeapon
  1180.  
  1181. ============
  1182. */
  1183. void() W_ChangeWeapon =
  1184. {
  1185.     local    float    it, am, fl;
  1186.  
  1187.     it = self.items;
  1188.     am = 0;
  1189.  
  1190.     if (self.impulse == 1)
  1191.     {
  1192.         if (morningstar && self.weapon == IT_AXE)
  1193.          fl = IT_MORNINGSTAR;
  1194.        else
  1195.          fl = IT_AXE;
  1196.     }
  1197.     else if (self.impulse == 2)
  1198.     {
  1199.         fl = IT_SHOTGUN;
  1200.         if (self.ammo_shells < 1)
  1201.             am = 1;
  1202.     }
  1203.     else if (self.impulse == 3)
  1204.     {
  1205.         fl = IT_SUPER_SHOTGUN;
  1206.         if (self.ammo_shells < 2)
  1207.             am = 1;
  1208.     }        
  1209.     else if (self.impulse == 4)
  1210.     {
  1211.         fl = IT_NAILGUN;
  1212.         if (self.ammo_nails < 1)
  1213.             am = 1;
  1214.     }
  1215.     else if (self.impulse == 5)
  1216.     {
  1217.         fl = IT_SUPER_NAILGUN;
  1218.         if (self.ammo_nails < 2)
  1219.             am = 1;
  1220.     }
  1221.   else if (self.impulse == 6)
  1222.     {
  1223.     if (self.weapon != IT_GRENADE_LAUNCHER)
  1224.       fl = IT_GRENADE_LAUNCHER;
  1225.     else
  1226.       fl = IT_FLAMETHROWER;
  1227.     if (self.ammo_rockets < 1)
  1228.             am = 1;
  1229.     }
  1230.     else if (self.impulse == 7)
  1231.     {
  1232.         fl = IT_ROCKET_LAUNCHER;
  1233.         if (self.ammo_rockets < 1)
  1234.             am = 1;
  1235.     }
  1236.     else if (self.impulse == 8)
  1237.     {
  1238.         fl = IT_LIGHTNING;
  1239.         if (self.ammo_cells < 1)
  1240.             am = 1;
  1241.     }
  1242.   else if (self.impulse == 50)
  1243.     {
  1244.     fl = IT_FLAMETHROWER;
  1245.     if (self.ammo_rockets < 1)
  1246.             am = 1;
  1247.     }
  1248.   else if (self.impulse == 51)
  1249.     {
  1250.         if (!morningstar)
  1251.         {
  1252.             self.impulse = 0;
  1253.             return;
  1254.         }
  1255.     fl = IT_MORNINGSTAR;
  1256.     }
  1257.  
  1258.     self.impulse = 0;
  1259.     
  1260.     if (!(self.items & fl))
  1261.     {    // don't have the weapon
  1262.         sprint (self, "no weapon.\n");
  1263.         return;
  1264.     }
  1265.  
  1266.     if (am)
  1267.     {    // don't have the ammo
  1268.         sprint (self, "not enough ammo.\n");
  1269.         return;
  1270.     }
  1271.  
  1272. //
  1273. // set weapon, set ammo
  1274. //
  1275.     self.weapon = fl;
  1276.   if (fl == IT_FLAMETHROWER)
  1277.     sprint (self, "Flamethrower\n");
  1278.   else if (fl == IT_GRENADE_LAUNCHER)
  1279.     sprint (self, "Grenade Launcher\n");
  1280.     W_SetCurrentAmmo ();
  1281. };
  1282.  
  1283. /*
  1284. ============
  1285. CheatCommand
  1286. ============
  1287. */
  1288. void() CheatCommand =
  1289. {
  1290.     if (deathmatch || coop)
  1291.         return;
  1292.  
  1293.     self.ammo_rockets = 100;
  1294.     self.ammo_nails = 200;
  1295.     self.ammo_shells = 100;
  1296.     self.items = self.items | 
  1297.         IT_AXE |
  1298.         IT_SHOTGUN |
  1299.         IT_SUPER_SHOTGUN |
  1300.         IT_NAILGUN |
  1301.         IT_SUPER_NAILGUN |
  1302.         IT_GRENADE_LAUNCHER |
  1303.     IT_FLAMETHROWER |
  1304.         IT_ROCKET_LAUNCHER |
  1305.         IT_KEY1 | IT_KEY2;
  1306.  
  1307.     self.ammo_cells = 200;
  1308.     self.items = self.items | IT_LIGHTNING;
  1309.  
  1310.     self.weapon = IT_ROCKET_LAUNCHER;
  1311.     self.impulse = 0;
  1312.     W_SetCurrentAmmo ();
  1313. };
  1314.  
  1315. /*
  1316. ============
  1317. CycleWeaponCommand
  1318.  
  1319. Go to the next weapon with ammo
  1320. ============
  1321. */
  1322. void() CycleWeaponCommand =
  1323. {
  1324.     local    float    it, am;
  1325.     
  1326.     it = self.items;
  1327.     self.impulse = 0;
  1328.     
  1329.     while (1)
  1330.     {
  1331.         am = 0;
  1332.  
  1333.         if (self.weapon == IT_LIGHTNING)
  1334.         {
  1335.             self.weapon = IT_AXE;
  1336.         }
  1337.         else if (self.weapon == IT_AXE)
  1338.     {
  1339.             if (morningstar)
  1340.           self.weapon = IT_MORNINGSTAR;
  1341.             else
  1342.             {
  1343.                 self.weapon = IT_SHOTGUN;
  1344.                 if (self.ammo_shells < 1)
  1345.                     am = 1;
  1346.             }
  1347.     }
  1348.     else if (self.weapon == IT_MORNINGSTAR)
  1349.         {
  1350.             self.weapon = IT_SHOTGUN;
  1351.             if (self.ammo_shells < 1)
  1352.                 am = 1;
  1353.         }
  1354.         else if (self.weapon == IT_SHOTGUN)
  1355.         {
  1356.             self.weapon = IT_SUPER_SHOTGUN;
  1357.             if (self.ammo_shells < 2)
  1358.                 am = 1;
  1359.         }        
  1360.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1361.         {
  1362.             self.weapon = IT_NAILGUN;
  1363.             if (self.ammo_nails < 1)
  1364.                 am = 1;
  1365.         }
  1366.         else if (self.weapon == IT_NAILGUN)
  1367.         {
  1368.             self.weapon = IT_SUPER_NAILGUN;
  1369.             if (self.ammo_nails < 2)
  1370.                 am = 1;
  1371.         }
  1372.         else if (self.weapon == IT_SUPER_NAILGUN)
  1373.         {
  1374.             self.weapon = IT_GRENADE_LAUNCHER;
  1375.             if (self.ammo_rockets < 1)
  1376.                 am = 1;
  1377.         }
  1378.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1379.         {
  1380.       self.weapon = IT_FLAMETHROWER;
  1381.             if (self.ammo_rockets < 1)
  1382.                 am = 1;
  1383.         }
  1384.     else if (self.weapon == IT_FLAMETHROWER)
  1385.         {
  1386.       self.weapon = IT_ROCKET_LAUNCHER;
  1387.             if (self.ammo_rockets < 1)
  1388.                 am = 1;
  1389.         }
  1390.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1391.         {
  1392.             self.weapon = IT_LIGHTNING;
  1393.             if (self.ammo_cells < 1)
  1394.                 am = 1;
  1395.         }
  1396.  
  1397.         if ( (self.items & self.weapon) && am == 0)
  1398.         {
  1399.       if (self.weapon == IT_FLAMETHROWER)
  1400.         sprint(self,"Flamethrower\n");
  1401.       else if (self.weapon == IT_GRENADE_LAUNCHER)
  1402.         sprint(self,"Grenade Launcher\n");
  1403.             W_SetCurrentAmmo ();
  1404.             return;
  1405.         }
  1406.     }
  1407. };
  1408.  
  1409. /*
  1410. ============
  1411. ServerflagsCommand
  1412.  
  1413. Just for development
  1414. ============
  1415. */
  1416. void() ServerflagsCommand =
  1417. {
  1418.     serverflags = serverflags * 2 + 1;
  1419. };
  1420.  
  1421. void() QuadCheat =
  1422. {
  1423.     if (deathmatch || coop)
  1424.         return;
  1425.     self.super_time = 1;
  1426.     self.super_damage_finished = time + 30;
  1427.     self.items = self.items | IT_QUAD;
  1428.     dprint ("quad cheat\n");
  1429. };
  1430.  
  1431.  
  1432. /*
  1433. ============
  1434. ImpulseCommands
  1435.  
  1436. ============
  1437. */
  1438. void() ImpulseCommands =
  1439. {
  1440.     if ( (self.impulse >= 1 && self.impulse <= 8)
  1441.       || (self.impulse >= 50 && self.impulse <= 51) )
  1442.         W_ChangeWeapon ();
  1443.     else if (self.impulse == 9)
  1444.         CheatCommand ();
  1445.     else if (self.impulse == 10)
  1446.         CycleWeaponCommand ();
  1447.     else if (self.impulse == 11)
  1448.         ServerflagsCommand ();
  1449.  
  1450.     // DD code.
  1451.     else if (self.impulse >= 150 && self.impulse <= 168)
  1452.     {
  1453.         if (!teamplay && deathmatch)
  1454.         {
  1455.             self.skin = self.impulse - 150;
  1456.             SkinName(self.skin);
  1457.             bprint(self.netname);
  1458.             bprint(" now has the ");
  1459.             bprint(skin_name);
  1460.             bprint(" Skin.\n");
  1461.         }
  1462.     }
  1463.     else if (self.impulse == 200)
  1464.     {
  1465.         if (!teamplay && deathmatch)
  1466.         {
  1467.             self.skin = self.skin + 1;
  1468.             if (self.skin > 18)
  1469.                 self.skin = 0;
  1470.             SkinName(self.skin);
  1471.             bprint(self.netname);
  1472.             bprint(" now has the ");
  1473.             bprint(skin_name);
  1474.             bprint(" Skin.\n");
  1475.         }
  1476.     }
  1477.     else if (self.impulse == 201)
  1478.     {
  1479.         if (!teamplay && deathmatch)
  1480.         {
  1481.             self.skin = self.skin - 1;
  1482.             if (self.skin < 0)
  1483.                 self.skin = 18;
  1484.             SkinName(self.skin);
  1485.             bprint(self.netname);
  1486.             bprint(" now has the ");
  1487.             bprint(skin_name);
  1488.             bprint(" Skin.\n");
  1489.         }
  1490.     }
  1491.     else if (self.impulse == 202)
  1492.     {
  1493.         local float team1;
  1494.         local float team2;
  1495.         local float team3;
  1496.         local float team4;
  1497.  
  1498.         if (self.start_team == 0)
  1499.         {
  1500.             // Get player count for each team.
  1501.             team1 = team2 = team3 = team4 = 0;
  1502.             other = find (world, classname, "player");
  1503.             while (other != world)
  1504.             {
  1505.                 if (other.start_team == actual_team1)
  1506.                     team1 = team1 + 1;
  1507.                 else if (other.start_team == actual_team2)
  1508.                     team2 = team2 + 1;
  1509.                 else if (other.start_team == actual_team3)
  1510.                     team3 = team3 + 1;
  1511.                 else if (other.start_team == actual_team4)
  1512.                     team4 = team4 + 1;
  1513.                 other = find (other, classname, "player");
  1514.             }
  1515.  
  1516.             if (teamplay < 0)  // Game of tag?
  1517.             {
  1518.                 sprint(self, "How about a game of tag?\n");
  1519.                 if (team1 && !team2)
  1520.                 {
  1521.                     ConfigTeam(2, 0);
  1522.                     sprint(self, "Tag!  You're IT!\n");
  1523.                     sprint(self, "Earn a bonus frag for each minute you survive.\n");
  1524.                     stuffcmd(self, color_team);
  1525.                     self.start_team = assigned_team;
  1526.                     parm11 = assigned_team;
  1527.                     self.team = assigned_team;
  1528.                     self.skin = skin_team;
  1529.                     parm10 = skin_team;
  1530.                     IT_time = time;
  1531.                 }
  1532.                 else
  1533.                 {
  1534.                     ConfigTeam(2, 0);
  1535.                     sprint(self, "Kill the IT player (");
  1536.                     sprint(self, team_name);
  1537.                     sprint(self, " with ");
  1538.                     sprint(self, skin_name);
  1539.                     sprint(self, " Skin) and earn 3 frags!\n");
  1540.                     ConfigTeam(1, 0);
  1541.                     stuffcmd(self, color_team);
  1542.                     self.start_team = assigned_team;
  1543.                     parm11 = assigned_team;
  1544.                     self.team = assigned_team;
  1545.                     self.skin = skin_team;
  1546.                     parm10 = skin_team;
  1547.                 }
  1548.             }
  1549.             else if (teamplay == 2)
  1550.             {
  1551.                 sprint(self, "This is a two team server.\n");
  1552.                 if (team1 <= team2)
  1553.                     SetTeam(1, 0);
  1554.                 else
  1555.                     SetTeam(2, 0);
  1556.             }
  1557.             else if (teamplay == 3)
  1558.             {
  1559.                 sprint(self, "This is a three team server.\n");
  1560.                 if (team1 <= team2 && team1 <= team3)
  1561.                     SetTeam(1, 0);
  1562.                 else if (team2 <= team3)
  1563.                     SetTeam(2, 0);
  1564.                 else
  1565.                     SetTeam(3, 0);
  1566.             }
  1567.             else  // 4 teams
  1568.             {
  1569.                 sprint(self, "This is a four team server.\n");
  1570.                 if (team1 <= team2 && team1 <= team3 && team1 <= team4)
  1571.                     SetTeam(1, 0);
  1572.                 else if (team2 <= team3 && team2 <= team4)
  1573.                     SetTeam(2, 0);
  1574.                 else if (team3 <= team4)
  1575.                     SetTeam(3, 0);
  1576.                 else
  1577.                     SetTeam(4, 0);
  1578.             }
  1579.         }
  1580.         else  // Attempt to switch sides.
  1581.         {
  1582.             if (teamplay < 0)
  1583.             {
  1584.                 if (self.start_team == actual_team2)
  1585.                 {
  1586.                     if (self.team == -1)  // Was a tag made?
  1587.                     {
  1588.                         bprint("Tag!  ");
  1589.                         bprint(self.netname);
  1590.                         bprint(" is now IT!\n");
  1591.                         IT_time = time;
  1592.                     }
  1593.                     else
  1594.                         sprint(self, "There's no avoiding it - You're IT!\n");
  1595.                 }
  1596.                 ConfigTeam(0, self.start_team);
  1597.                 stuffcmd(self, color_team);
  1598.                 self.start_team = assigned_team;
  1599.                 parm11 = assigned_team;
  1600.                 self.team = assigned_team;
  1601.                 self.skin = skin_team;
  1602.                 parm10 = skin_team;
  1603.             }
  1604.             else if (self.team != self.start_team)
  1605.                 ResetTeam(0, self.start_team);
  1606.         }
  1607.     }
  1608.  
  1609.     else if (self.impulse == 255)
  1610.         QuadCheat ();
  1611.         
  1612.     self.impulse = 0;
  1613. };
  1614.  
  1615. /*
  1616. ============
  1617. W_WeaponFrame
  1618.  
  1619. Called every frame so impulse events can be handled as well as possible
  1620. ============
  1621. */
  1622. void() W_WeaponFrame =
  1623. {
  1624.     if (time < self.attack_finished)
  1625.         return;
  1626.  
  1627.     ImpulseCommands ();
  1628.  
  1629. // check for attack
  1630.     if (self.button0)
  1631.     {
  1632.         SuperDamageSound ();
  1633.         W_Attack ();
  1634.     }
  1635. };
  1636.  
  1637. /*
  1638. ========
  1639. SuperDamageSound
  1640.  
  1641. Plays sound if needed
  1642. ========
  1643. */
  1644. void() SuperDamageSound =
  1645. {
  1646.     if (self.super_damage_finished > time)
  1647.     {
  1648.         if (self.super_sound < time)
  1649.         {
  1650.             self.super_sound = time + 1;
  1651.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1652.         }
  1653.     }
  1654.     return;
  1655. };
  1656.